<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自定义对象</title>
</head>
<body>

<table border="1">
    <caption>商品列表</caption>
    <tr>
        <th>商品名</th><th>价格</th><th>库存</th>
    </tr>
</table>
<script>
    function Person() {}
    let p1 = new Person();
    p1.name = "刘德华";
    p1.age = 18;
    p1.run = function () {
      console.log(this.name+":"+this.age);
    }
    p1.run();
    function Car() {
        this.name = "宾利";
        this.price = 500;
        this.run = function () {
            console.log(this.name+":"+this.price);
        }
    }
    let c1 = new Car();
    c1.name = "宝马";
    c1.run();
    let p2 = {};
    p2.name = "貂蝉";
    p2.age = 18;
    p2.run = function () {
        console.log(this.name+":"+this.age);
    }
    p2.run();
    let p3 = {
        name:"貂蝉",
        age:18,
        run : function () {
            console.log(this.name+":"+this.age);
        }
    }
    p3.run();
    let arr = [{title: "小米",price:5000,num:500},
        {title: "华为",price:4000,num:400},
        {title: "中兴",price:3000,num:300},
    ]
    let t = document.querySelector("table");
    for (let item of arr) {
        let tr = document.createElement("tr");
        let titleTd = document.createElement("td");
        let priceTd = document.createElement("td");
        let numTd = document.createElement("td");
        titleTd.innerText = item.title;
        priceTd.innerText = item.price;
        numTd.innerText = item.num;
        tr.append(titleTd,priceTd,numTd);
        t.append(tr);
    }
</script>
</body>
</html>